using System.Collections.Generic;
using UnityEngine;
using Verse;
using RimWorld;
using Verse.Sound;
using UnityEngine.AI;

namespace RimZombieGirl
{
    public class CompAbilityEffect_DirtTeleport : CompAbilityEffect
    {
        public new CompProperties_DirtTeleport Props => (CompProperties_DirtTeleport)props;

        public Pawn Caster => parent.pawn;

        public override bool AICanTargetNow(LocalTargetInfo target)
        {
            return true;
        }

        public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
        {

            // 获取起始位置
            IntVec3 start = Caster.Position;

            if (Props.targetSound != null)
            {
                // 播放落点声音
                Props.targetSound.PlayOneShot(new TargetInfo(target.Cell, Caster.Map));
            }

            if (Props.targetEffect != null)
            {
                // 播放路径特效
                Effecter effecter = Props.targetEffect.Spawn();

                effecter.Trigger(new TargetInfo(start, Caster.Map), new TargetInfo(target.Cell, Caster.Map));
            }

            // 传送Caster到目标位置
            Caster.Position = target.Cell;

            if (Props.targetMote != null)
            {
                // 播放落点特效
                MoteMaker.MakeStaticMote(target.Cell, Caster.Map, Props.targetMote);
            }
        }
    }
}